Jx.declare('Jx.lib.Number', {

	$singleton: true,

	__ref_CompareOperators: {

		'>' : function(r){

			return r > 0;

		},

		'>=' : function(r){

			return r >= 0;

		},

		'<=' : function(r){

			return r <= 0;

		},

		'<' : function(r){

			return r < 0;

		},

		'=' : function( r ){

			return !r;

		},

		'!=': function(n1, n2){

			return r != 0;

		}

	},

	__re_MultiDecimal: /^[0-9]+(\.[0-9]+)*$/,

	count: function(num){

		return Math.floor((Math.log(num) / Math.log(10)) + 1);

	},

	bytes: function(x){

		for (var n = 0; x > 0;) {

			x >>= 8;

			n ++;

		}

		return n;

	},

	compare: function(op, n1, n2, all){

		var cmpo = this.__ref_CompareOperators,

			J = Jx,

			fn = cmpo.hasOwnProperty(op) && cmpo[op],

			c1 = J.isScalar(n1) ?

				String(n1).split('.')

				:

				[],

			c2 = J.isScalar(n2) ?

				String(n2).split('.')

				:

				[],

			ret = false,

			l = Math[ all !== false ? 'max' : 'min' ](c1.length, c2.length);

		if (J.isFunction(fn) && l){

			ret = true;

			for(var result, c=0; c<l; c++){

				n1 = parseInt( c in c1 ? c1[c] : undefined, 10) || 0;

				n2 = parseInt( c in c2 ? c2[c] : undefined, 10) || 0;

				result = n1 - n2;

				//-- compare!
				if ( result || c == l-1){

					return fn( result );

				}

			}

		}

		return ret;

	},

	numericToArray: function(n){

		var J = Jx;

		if (J.isNumber(n)){

			n = n.toString();

		}

		return J.isString(n) && this.__re_MultiDecimal.test(n) ?

			n.split('.')

			:

			void(0);


	},

	hasCollision:function(s1, s2, t1, t2){

		var t;

		if (s1 > s2){

			t = s1;

			s1 = s2;

			s2 = t;

		}

		if (t1 > t2){

			t = t1;

			t1 = t2;

			t2 = t;

		}

		return (s1 <= t2) && (s2 >= t1);

	}


});
